﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using EZMemoLib;

namespace UnitTestProject
{
    [TestClass()]
    public class PlayerTest
    {


        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        public void ParseVoicePartTest()
        {
            string voicePartString = "[00:08.200][00:09.123][L]"; 
            VoicePart actual;
            actual = Player.ParseVoicePart(voicePartString);

            if (actual != null)
            {
                Assert.IsTrue (actual.PartStart.Seconds  == 8   );
                Assert.IsTrue(actual.PartStart.Milliseconds == 200);

                Assert.IsTrue(actual.PartEnd.Seconds == 9);
                Assert.IsTrue(actual.PartEnd.Milliseconds == 123);

                Assert.IsTrue(actual.FileMark == "L");

                //Assert.AreEqual(expected, actual);
            }
            
        }

        [TestMethod()]
        public void ParseTimeSpanTest()
        {
            string timeString = "0:00:08.200"; 
            TimeSpan actual = Player.ParseTimeSpan(timeString);
            Assert.IsTrue(actual.Seconds == 8);
            Assert.IsTrue(actual.Milliseconds == 200);
        }

        [TestMethod()]
        public void BuildVoicePartTest()
        {
            VoicePart part = new VoicePart
            {
                FileMark = "L",
                PartStart = new TimeSpan(0, 0, 0, 8, 200),
                PartEnd = new TimeSpan(0, 0, 0, 9, 123)
            };

            string voicePartString = "[0:00:08.2][0:00:09.123][L]"; 
            string actual;
            actual = Player.BuildVoicePart(part);
            Assert.AreEqual(voicePartString, actual);

        }

        [TestMethod()]
        public void ParseVoicePartLrcTest()
        {
            //[al:新概念英语（二）]
            //[ar:MP3 同步字幕版（美音）]
            //[ti:In or Out?]
            //[by:更多学习内容，请到VeryCD.com搜索“露珠”]
            //[00:11.22]Why did Rex run away?
            //[00:15.52]Our dog, Rex, used to sit outside our front gate and bark.
            //[00:22.54]Every time he wanted to come into the garden he would bark until someone opened the gate.
            //[00:30.39]As the neighbours complained of the noise, my husband spent weeks training him to press his paw on the latch to let himself in.
            //[00:41.56]Rex soon became an expert at opening the gate.
            //[00:46.22]However, when I was going out shopping last week, I noticed him in the garden near the gate.
            //[00:54.81]This time he was barking so that someone would let him out!
            //[01:00.09]Since then, he has developed another bad habit.
            //[01:05.10]As soon as he opens the gate from the outside, he comes into the garden and waits until the gate shuts.
            //[01:14.07]Then he sits and barks until someone lets him out.
            //[01:18.58]After this he immediately lets himself in and begins barking again.
            //[01:26.28]Yesterday my husband removed the gate and Rex got so annoyed we have not seen him since.

            string lrcLineString = "[00:11.22]Why did Rex run away?";
            string lrcLineString2 = "[00:15.52]Our dog, Rex, used to sit outside our front gate and bark.";
            VoicePart actual = Player.ParseVoicePartLrc(lrcLineString, lrcLineString2);

            Assert.IsTrue(actual.PartStart.TotalMilliseconds == 11220 );
            Assert.IsTrue(actual.PartEnd.TotalMilliseconds == 15520 );
            Assert.IsTrue(actual.FileMark == "Why did Rex run away?");

            //for head
            lrcLineString = "[al:新概念英语（二）]";
            lrcLineString2 = "[ar:MP3 同步字幕版（美音）]";
            actual = Player.ParseVoicePartLrc(lrcLineString, lrcLineString2);

            Assert.IsTrue(actual== null);

            //for head2
            lrcLineString = "[al:新概念英语（二）]";
            lrcLineString2 = "[00:11.22]Why did Rex run away?";
            actual = Player.ParseVoicePartLrc(lrcLineString, lrcLineString2);

            Assert.IsTrue(actual == null);


            //for end
            lrcLineString = "[01:26.28]Yesterday my husband removed the gate and Rex got so annoyed we have not seen him since.";
            lrcLineString2 = "";
            actual = Player.ParseVoicePartLrc(lrcLineString, lrcLineString2);

            Assert.IsTrue(actual.PartStart.TotalMilliseconds == 86280);
            Assert.IsTrue(actual.PartEnd.TotalMilliseconds == 0);
            Assert.IsTrue(actual.FileMark == "Yesterday my husband removed the gate and Rex got so annoyed we have not seen him since.");

        }
    }
}
